<?php
use yii\helpers\Url;
use app\data\StaffData;
use yii\bootstrap\ActiveForm;
$this->context->layout=false;

?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<?php 
	$form = ActiveForm::begin([
		'id' => 'm-form',
        'options' => [
        	'class' => 'form-horizontal'
        ]
    ]);

?>

	<div id="other-content" style="margin:15px;">


		<div class="panel panel-default">
			<div class="panel-heading">经历描述</div>
			<div class="panel-body m-panel-body">
				<div class="m-box">
					<div class="m-box">
						<textarea name="comment" class="k-textbox"  spellcheck="false" style="overflow: hidden; height: 100px;width: 100%"><?=$oData['staff_ext']['comment'] ?></textarea>
					</div>
				</div>
			</div>
		</div>
		<br>
		<div class="panel panel-default">
			<div class="panel-heading">教育经历</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-education" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						
						<table class="table" id="education-table" style="margin-top:10px">
							<?php foreach ($oData['education_ext'] as $key => $value):?>
							<tr class="m-table-row m-tr" data-id="<?=$value['id']; ?>">
								<td>
									<input type="hidden" name="education_id[]" value="<?=$value['id'] ?>"/>
									开始时间
								</td>
								<td><input type="text" id="start_date_<?=$value['id']; ?>" name="education_start_date_arr[]" style="width:121px;float:left;" value="<?=date("m/d/Y",strtotime($value['start_date'])); ?>"></td>
								<td>结束时间</td>
								<td><input type="text" id="end_date_<?=$value['id']; ?>" name="education_end_date_arr[]" style="width:121px;float:left;" value="<?=date("m/d/Y",strtotime($value['end_date'])); ?>"></td>
								<td>教育机构</td>
								<td><input type="text" class="k-input k-textbox" name="education_organization_arr[]" style="width:121px;float:left;" value="<?=$value['education_organization']; ?>"></td>
								<td>专业</td>
								<td><input type="text" class="k-input k-textbox" name="education_major_arr[]" style="width:121px;float:left;" value="<?=$value['major']; ?>"></td>
								<td>学历</td>
								<td><input type="text" id="education_<?=$value['id']; ?>" name="educational_arr[]" style="width:121px;float:left;" ></td>
								<td><a href="javascript:;" class="del-education"><i class="glyphicon glyphicon-remove"></i></a></td>
							</tr>
							<?php endforeach; ?>
						</table>
					</div>
			  	</div>
			</div>
		</div>

		<br>
		<div class="panel panel-default">
			<div class="panel-heading">员工证书</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-certificate" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>

						<table class="table" id="certificate-table" style="margin-top:10px">
							<?php foreach ($oData['certificate_ext'] as $key => $value):?>
							<tr class="m-tr" data-id="<?=$value['id'] ?>">
								<th width="16%">
								<input type="hidden" name="certificate_id[]" value="<?=$value['id'] ?>"/>
									时间：
								</th>
								<td width="16%">
									<input type="text" id="get_date_<?=$value['id'] ?>" name="certificate_get_date_arr[]" style="width:120px;" value="<?=date('m/d/Y',strtotime($value['get_date'])) ?>">
								</td>
								<th width="16%">
									名称：
								</th>
								<td width="16%">
									<input type="text" class="k-input k-textbox" name="certificate_name_arr[]" style="width:120px;" value="<?=$value['certificate_name'] ?>">
								</td>
								<th width="16%">
									成绩：
								</th>
								<td width="16%">
									<input type="text" class="k-input k-textbox" name="certificate_result_arr[]" style="width:120px;" value="<?=$value['result'] ?>">
								</td>
								<td width="1%">
									<a href="javascript:;" class="del-certificate"><i class="glyphicon glyphicon-remove"></i></a>
								</td>
							</tr>
							<?php endforeach; ?>
						</table>
			  	</div>
			</div>
		</div>
		<br>

		<div class="panel panel-default">
			<div class="panel-heading">家庭成员</div>
			<div class="panel-body m-panel-body">
				<div class="m-box">
			  		<div class="m-box">	
			  			<a type="button" id="add-member" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						<table class="table" id="member-table" style="margin-top:10px">
							<?php foreach ($oData['member_ext'] as $key => $value):?>
							<tr class="m-table-row m-tr" data-id="<?=$value['id'] ?>">
								<td>姓名<input type="hidden" name="member_id[]" value="<?=$value['id'] ?>"/></td>
								<td>
									<input type="text" class="k-input k-textbox" name="member_name_arr[]" style="width:121px;float:left;" value="<?=$value['member_name'] ?>">
								</td>
								<td>关系</td>
								<td>
									<input type="text" class="k-input k-textbox" name="member_relationship_arr[]" style="width:121px;float:left;" value="<?=$value['relationship'] ?>">
								</td>
								<td>工作单位</td>
								<td>
									<input type="text" class="k-input k-textbox" name="member_work_unit_arr[]" style="width:121px;float:left;" value="<?=$value['work_unit'] ?>">
								</td>
								<td>职业</td>
								<td>
									<input type="text" class="k-input k-textbox" name="member_position_name_arr[]" style="width:121px;float:left;" value="<?=$value['member_position_name'] ?>">
								</td>
								<td>电话</td>
								<td>
									<input type="text" class="k-input k-textbox" name="member_tel_arr[]" style="width:121px;float:left;" value="<?=$value['tel'] ?>">
								</td>
								<td><a href="javascript:;" class="del-member"><i class="glyphicon glyphicon-remove"></i></a><td>
							</tr>
							<?php endforeach; ?>
						</table>
					</div>
				</div>		
			</div>
		</div>
		<br>
		<div class="panel panel-default">
			<div class="panel-heading">工作经验</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-word" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						<table class="table" id="work-table" style="margin-top:10px">

							<?php foreach ($oData['work_ext'] as $key => $value):?>
							<tr class="m-table-row m-tr" data-id="<?=$value['id'] ?>">
								<td>
									<input type="hidden" name="word_id[]" value="<?=$value['id'] ?>"/>
									开始时间
								</td>
								<td>
									<input type="text" id="start_date_<?=$value['id'] ?>" name="word_start_date_arr[]" style="width:121px;float:left;" value="<?=date('m/d/Y',strtotime($value['start_date'])) ?>">
								</td>
								<td>结束时间</td>
								<td>
									<input type="text" id="end_date_<?=$value['id'] ?>" name="word_end_date_arr[]" style="width:121px;float:left;" value="<?=date('m/d/Y',strtotime($value['end_date'])) ?>">
								</td>
								<td>单位名称</td>
								<td>
									<input type="text" class="k-input k-textbox" name="word_unit_name_arr[]" style="width:121px;float:left;" value="<?=$value['unit_name'] ?>">
								</td>
				
								<td>职位</td>
								<td>
									<input type="text" class="k-input k-textbox" name="word_position_name_arr[]" style="width:121px;float:left;" value="<?=$value['position_name'] ?>">
								</td>
								<td>离职原因</td>
								<td>
									<input type="text" class="k-input k-textbox" name="word_leave_reason_arr[]" style="width:121px;float:left;" value="<?=$value['leave_reason'] ?>">
								</td>
								<td>
									<a href="javascript:;" class="del-work"><i class="glyphicon glyphicon-remove"></i></a>
								</td>
							</tr>
							<?php endforeach; ?>
						</div>
					</table>
			  	</div>
			</div>
		</div>


		<br>
		<div class="panel panel-default">
			<div class="panel-heading">员工福利</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
						<div id="word-box_add">
							<table class="table">

                                <tr>
                                    <th  width="25%">
                                        真实生日：
                                    </th>
                                    <td width="25%">
                                        <input type="text" name="real_birthday" value=" <?=@$oData['staff_ext']['real_birthday'] ?>">
                                    </td>
                                    <th width="25%">
                                        星座：
                                    </th>
                                    <td width="25%">
                                        <input type="text" name="constellation" class="k-input k-textbox" value="<?=@$oData['staff_ext']['constellation'] ?>" readonly>
                                    </td>

                                </tr>

								<tr>
									<th>
										停车类型：
									</th>
									<td colspan="3">
										<input type="text"  id="park_type" name="park_type">
									</td>
								
								</tr>
							</table>
						</div>
			  		</div>
				</div>
			</div>
		</div>
        <br>
            <div class="panel panel-default">
                <div class="panel-heading">其他设置</div>
                <div class="panel-body m-panel-body">
                    <div class="m-box">
                        <div class="m-box">
                            <table class="table">
                                <tr>
                                    <td>是否管理员:</td>
                                    <td><input id="visible-switch" name="is_manager" aria-label="Visible Switch" /></td>
                                    <td>有技能补贴:</td>
                                    <td><input id="name-switch" name="is_skills_subsidy" aria-label="Name Switch" /></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <?php if(!empty($oData['staff_ext'])): ?>
                <script>
                    $(function () {
                        $("#visible-switch").kendoMobileSwitch({
                            <?php if ($oData['staff_ext']->is_manager == 1): ?>checked: true <?php endif; ?>
                        });
                        $("#name-switch").kendoMobileSwitch({
                            <?php if ($oData['staff_ext']->is_skills_subsidy == 1): ?>checked:true <?php endif; ?>
                        });
                    })
                </script>

            <?php endif; ?>
	</div>

	<a type="button" class="k-button k-button-icontext" id="m-submit" href="javascript:;" style="margin-top:20px;float:right;">
		<i class="glyphicon glyphicon-plus"></i>提交
	</a>
<?php ActiveForm::end(); ?>
<script>


//學歷
var _educationData = JSON.parse('<?=json_encode(StaffData::getEducation()); ?>');



$(function(){

    $("input[name='real_birthday']").kendoDatePicker({
        format: "MM-dd",
        depth:"day",
        start:"year",
        change:function(e){
            var _this = this;
            kendo.ui.progress($("#other-content"), true);

            $.ajax({
                url:"<?=Url::to(['getconstellation']); ?>",
                type:"GET",
                dataType:"json",
                data:{date : _this._oldText},
                complete:function (e) {
                    kendo.ui.progress($("#other-content"), false);
                },
                error:function (e) {
                    if(e.statusCode != 200){
                        layer.msg(e.statusText);
                    }
                },
                success:function (redata) {
                    if(!$.isEmptyObject(redata)){
                        $("input[name='constellation']").val(redata.text);
                    }
                }
            });
        }
    });

	$("#m-submit").click(function(){
		var _this=$(this);
		_this.parents("#m-form").ajaxSubmit({
			url : "<?=Url::to(['update']); ?>",
			data:{id:"<?=$oData['id']; ?>"},
			dataType:"json",
			success:function(redata){
				if(redata.status==1){
					var _editWindow = editWindow.data('kendoWindow');
				    _editWindow.refresh();
				    _grid.data("kendoGrid").dataSource.read();
				    _grid.data("kendoGrid").refresh();
					_editWindow.close();
				}else{
					layer.msg(redata.info, {icon: 5});
				}
			}
		})
	})

	$(".del-certificate").click(function(e){
		var _this = $(this);
		var _id = $(this).parents(".m-tr").data("id")
		$.ajax({
			url :"<?=Url::to(['delcertificate']); ?>",
			data:{certificate_id:_id},
			dataType:"json",
			type:"GET",
			success:function(d){
				if(d.status == 1){
					_this.parents(".m-tr").remove();
				}else{
					layer.msg(d.info, {icon: 5});
				}
			}
		})
	})

	$(".del-education").click(function(e){
		var _this = $(this);
		var _id = $(this).parents(".m-tr").data("id")

		$.ajax({
			url :"<?=Url::to(['deleducation']); ?>",
			data:{education_id:_id},
			dataType:"json",
			type:"GET",
			success:function(d){
				if(d.status == 1){
					_this.parents(".m-tr").remove();
				}else{
					layer.msg(d.info, {icon: 5});
				}
			}
		})
	})

	$(".del-member").click(function(e){
		var _this = $(this);
		var _id = $(this).parents(".m-tr").data("id")
	
		$.ajax({
			url :"<?=Url::to(['delmember']); ?>",
			data:{member_id:_id},
			dataType:"json",
			type:"GET",
			success:function(d){
				if(d.status == 1){
					_this.parents(".m-tr").remove();
				}else{
					layer.msg(d.info, {icon: 5});
				}
			}
		})
	})

	$(".del-work").click(function(e){
		var _this = $(this);
		var _id = $(this).parents(".m-tr").data("id")

		$.ajax({
			url :"<?=Url::to(['delwork']); ?>",
			data:{work_id:_id},
			dataType:"json",
			type:"GET",
			success:function(d){
				if(d.status == 1){
					_this.parents(".m-tr").remove();
				}else{
					layer.msg(d.info, {icon: 5});
				}
			}
		})
	})




	 $("#park_type").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource:JSON.parse('<?=json_encode(StaffData::getParkType()) ?>'),
        index:<?=StaffData::getSelectIndex($oData['park_type'],StaffData::getParkType()); ?>
    })

 

    <?php foreach ($oData['education_ext'] as $key => $value):?>
	    $("#start_date_<?=$value['id'] ?>").kendoDatePicker({format:"MM/dd/yyyy"});
	    $("#end_date_<?=$value['id'] ?>").kendoDatePicker({format:"MM/dd/yyyy"});
	    $("#education_<?=$value['id'] ?>").kendoDropDownList({
	        dataTextField: "text",
	        dataValueField: "value",
	        dataSource: _educationData,
	        index:<?=StaffData::getSelectIndex($value['educational'],StaffData::getEducation()); ?>
	    })
    <?php endforeach; ?>

    <?php foreach ($oData['certificate_ext'] as $key => $value):?>
    	$("#get_date_<?=$value['id'] ?>").kendoDatePicker({format:"MM/dd/yyyy"});
    <?php endforeach ?>

    <?php foreach ($oData['work_ext'] as $key => $value):?>
    	$("#start_date_<?=$value['id'] ?>").kendoDatePicker({format:"MM/dd/yyyy"});
    	$("#end_date_<?=$value['id'] ?>").kendoDatePicker({format:"MM/dd/yyyy"});
    <?php endforeach ?>

	$("#add-certificate").click(function(e){
		var _guid = guid();

		var _html = '<tr>\
			<th width="16%">\
			<input type="hidden" name="certificate_id[]" />\
				时间：\
			</th>\
			<td width="16%">\
				<input type="text" id='+_guid+' name="certificate_get_date_arr[]" style="width:120px;">\
			</td>\
			<th width="16%">\
				名称：\
			</th>\
			<td width="16%">\
				<input type="text" class="k-input k-textbox" name="certificate_name_arr[]" style="width:120px;">\
			</td>\
			<th width="16%">\
				成绩：\
			</th>\
			<td width="16%">\
				<input type="text" class="k-input k-textbox" name="certificate_result_arr[]" style="width:120px;">\
			</td>\
			<td width="1%">\
				<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
			</td>\
		</tr>';

		$("#certificate-table").append(_html);

		$("#"+_guid).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

		$(".del-row").click(function(e){
			$(this).parents("tr").remove();
		})

	});

	var _idIndex = 0;
	$("#add-education").click(function(e){
		var _startId = guid();

		var _endId = guid();

		var _education = guid();

		var _html = '<tr class="m-table-row">\
			<td>开始时间<input type="hidden" name="education_id[]" /></td>\
			<td>\
				<input type="text" id='+_startId+' name="education_start_date_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>结束时间</td>\
			<td>\
				<input type="text" id='+_endId+' name="education_end_date_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>教育机构</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="education_organization_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>专业</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="education_major_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>学历</td>\
			<td>\
				<input type="text" id='+_education+' name="educational_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>\
				<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
			</td>\
		</tr>';

		$("#education-table").append(_html);

		$("#"+_startId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

    	$("#"+_endId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

    	$("#"+_education).kendoDropDownList({
	        dataTextField: "text",
	        dataValueField: "value",
	        dataSource: JSON.parse('<?=json_encode(StaffData::getEducation()); ?>'),
	      	index:-1
	    })

		$(".del-row").click(function(e){
			$(this).parents(".m-table-row").remove();
		})
	});

	$("#add-member").click(function(e){
		var _html = '<tr class="m-table-row">\
			<td>姓名<input type="hidden" name="member_id[]" /></td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="member_name_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>关系</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="member_relationship_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>工作单位</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="member_work_unit_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>职业</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="member_position_name_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>电话</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="member_tel_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>\
				<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
			<td>\
		</div>';

		$("#member-table").append(_html);

		$(".del-row").click(function(e){
			$(this).parents(".m-table-row").remove();
		})
	})


	$("#add-word").click(function(e){

		var _startId = guid();

		var _endId = guid();

		var _html = '<tr class="m-table-row">\
			<td>\
				<input type="hidden" name="word_id[]" />\
				开始时间\
			</td>\
			<td>\
				<input type="text" id='+_startId+' name="word_start_date_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>结束时间</td>\
			<td>\
				<input type="text" id='+_endId+' name="word_end_date_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>单位名称</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="word_unit_name_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>职位</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="word_position_name_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>离职原因</td>\
			<td>\
				<input type="text" class="k-input k-textbox" name="word_leave_reason_arr[]" style="width:121px;float:left;">\
			</td>\
			<td>\
				<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
			</td>\
		</tr>';

		$("#work-table").append(_html);

		$("#"+_startId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

    	$("#"+_endId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

		$(".del-row").click(function(e){
			$(this).parents(".m-table-row").remove();
		})
	})
})




function guid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
    });
}



</script>